package feng.demo.controller.mer;

import feng.demo.entity.Breed;
import feng.demo.entity.Breeds;
import feng.demo.entity.XJson;
import feng.demo.service.BreedService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/mer/breed")
public class MerBreedController {
    @Autowired
    BreedService breedService;


    @GetMapping("/findAll")
    public String findAll(){
        Map<String,Object> map=new HashMap<>();
        List<Breeds> breeds = breedService.findAlls();
        map.put("breed",breeds);
        return new XJson(200,"",map).toString();
    }
    @GetMapping("/findById/{id}")
    public String findByid(@PathVariable("id")Integer breedid){

        Breed breed = breedService.findById(breedid);

        return new XJson(200,"",breed).toString();
    }

    @PostMapping("/add")
    public String add(Breed breed){

        breedService.add(breed);

        return new XJson(200,"添加成功","").toString();
    }
    @PostMapping("/update")
    public String update(Breed breed){
        breedService.update(breed);

        return new XJson(200,"修改成功","").toString();
    }

    @GetMapping("/del/{id}")
    public String del(@PathVariable("id") Integer breedid){

        breedService.del(breedid);
        List<Breeds> breeds = breedService.findAlls();
        return new XJson(200,"删除成功",breeds).toString();

    }



}
